<template>
  <div>
    <h3 style="margin-left:20px">修改</h3>
  </div>
  <el-form ref="ruleFormRef"
           :model="route"
           :rules="rules"
           label-width="120px"
           class="demo-ruleForm"
           status-icon>
    <el-form-item label="地址"
                  prop="name">
      <el-input v-model="state.formdata.name"
                placeholder="请修改地址"
                clearable
                style="width: 250px;"
                type="text" />
    </el-form-item>

  </el-form>
  <div class="subm">
    <el-button size="small" @click="info">取消</el-button>
    <el-button type="primary"
               size="small"
               @click="add">修改</el-button>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from "@vue/reactivity";
import { ElMessage } from "element-plus";
import { editdata } from "../../api/address";
import { useRoute, useRouter } from "vue-router";
const route:any = useRoute();
const router = useRouter();

const detail = JSON.parse(route.query.row);
const state = reactive<any>({
  formdata: {
    id: detail.id,
    name: detail.name,
  },
});

const rules = reactive({
  name: [{ required: true, message: "请填写地址", trigger: "blur" }],
});
const add = async () => {
  let res: any = await editdata(state.formdata);

  if (res.code == 10000) {
    ElMessage({
      message: "修改成功",
      type: "success",
    });
    router.push("/address/addresslist");
  } else {
    return alert("数据错误");
  }
};
const info=()=>{
  router.push("/address/addresslist");
}
</script>

<style lang="less" scoped>
.subm {
  margin: 10px 0 0 150px;
}
</style>